package com.article.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.article.entity.Category;
import com.article.jsonfactory.ConvertJsonUtils;
import com.article.service.ICategoryService;

@SuppressWarnings("serial")
public class CatetoryAction extends BaseAction implements ServletRequestAware {
	//private HttpServletRequest request;
	private ICategoryService categoryService;
	private Category category;
	
	/**
	 * 查询所有文章类别
	 * @return
	 */
	public String showCate(){
		List<Category> list = categoryService.findAll();
		String json = ConvertJsonUtils.convertListToJson(list);
		outJson(json);
		return null;
	}
	
	/**
	 * 添加文章类别
	 * @return
	 */
	public String add(){
		boolean result = categoryService.addCategory(category);
		outJson("{success:" + result + ", errorMsg:\"添加失败！请重新添加或联系管理员！\"");
		return null;
	}
	
	public void setServletRequest(HttpServletRequest arg0) {
		//request = arg0;
	}

	public void setCategoryService(ICategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

}
